package com.xc.freeapp.account.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xc.freeapp.bean.AuthInfo;
import com.xc.freeapp.entity.AppImage;
import com.xc.freeapp.entity.AppVersion;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.service.AppVersionService;
import com.xc.freeapp.util.AuthUtil;
import com.xc.freeapp.util.TokenAnnotation;
import com.xc.freeapp.util.UploadUtil;

@Controller
@RequestMapping("/appversion")
@Api(value = "/appversion" ,description="app版本")
public class AppVersionController extends AbstractController {
	@Autowired
	AppVersionService appVersionService;
	/**
	 * 获取图片
	 */
	@TokenAnnotation(required=false)
	@RequestMapping(value = "", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "获取最新版本")
	public  AppVersion getAppVersion(@RequestParam String versionNo,@RequestParam(required=false) String appid)throws BaseException {
		AuthInfo authInfo = AuthUtil.getAuthInfo(getRequest());
		if(appid==null||"".equals(appid)){
			appid=authInfo.getAppId();
		}
		 
		//根据版本号判断是否需要强制更新
		AppVersion appVersion =appVersionService.getAppVersionByVersionNO(appid,versionNo);
		List<AppVersion> appVersions = appVersionService.getAppVersionByBusinessid(Integer.valueOf(appid));
		appVersions.get(0).setIsautoupdate(appVersion.getIsautoupdate());
		appVersions.get(0).setIsupdate(appVersion.getIsupdate());
		appVersions.get(0).setAppurl(UploadUtil.urlConversion(appVersions.get(0).getAppurl()));
		return appVersions.get(0);
	}

}
